<template>
    <div class="rotationChart">
        <el-carousel :interval="4000" type="card" height="400px">
            <el-carousel-item v-for="item in 6" :key="item">
            </el-carousel-item>
        </el-carousel>
    </div>
    <div class="box">
        <div class="articleContent">
            <div class="articleContentson">
                <h1 :class="{ 'TextColor': !isBool }">我的文章</h1>
                <div class="Suspension">
                    <!-- 写文章按钮 -->
                    <el-tooltip class="box-item" effect="dark" content="如果你想写创作" placement="left">
                        <el-row class="elrow1"><el-button type="primary" :icon="Edit" :bg="true" circle
                                @click="dialogFormVisible = true" /></el-row>
                    </el-tooltip>
                    <!-- 写文章弹出框 -->
                    <el-dialog v-model="dialogFormVisible" title="发布文章" class="eldialog" align-center>
                        <div class="fillIn">
                            <div>
                                <label for=""><span>*</span> Title:</label>
                                <input type="text" v-model="fillInTheTitle" placeholder="文章标题">
                            </div>
                            <div>
                                <label for=""><span>*</span> Content:</label>
                                <textarea name="" id="" cols="50" rows="10" v-model="fillInTheContent"
                                    placeholder="文章内容"></textarea>
                            </div>
                        </div>
                        <div class="button">
                            <button @click="Cancel">取消</button>
                            <button @click="Release">发布</button>
                        </div>
                    </el-dialog>
                    <el-dropdown>
                        <!-- 删除文章 按钮 -->
                        <el-row class="elrow2"><el-button type="danger" :icon="Delete" circle /></el-row>
                        <template #dropdown>
                            <div v-for="(item, i) in store.articleTheme" :key="i" class="deleteList">
                                <h3>{{ item.Title }}
                                    <span><el-button type="danger" :icon="Delete" circle
                                            @click="DeleteButton(item.id)" /></span>
                                </h3>
                            </div>
                        </template>
                    </el-dropdown>
                </div>
                <div class="showarticleContent" :class="{ 'backgroudColor': !isBool }" v-for="(item, i) in store.ShowData"
                    :key="i">
                    <h2 :class="{ 'TextColor': !isBool }">{{ item.Title }}</h2>
                    <p :class="{ 'TextColor': !isBool }">{{ item.Content }}</p>
                </div>
                <Pager />
            </div>
            <div class="top" :class="{ 'backgroudColor': !isBool }">
                <span :class="{ 'TextColor': !isBool }">个人信息</span>
                <div class="img">
                    <img src="../assets/QQ图片20230425204111.jpg" alt="">
                </div>
                <span class="name" :class="{ 'TextColor': !isBool }">
                    {{ store.$state.Name }}
                </span>
                <div class="label" :class="{ 'TextColor': !isBool }">
                    <div class="labelcontext">
                        <p>文章</p>
                        <span>{{ article }}</span>
                    </div>
                    <div class="labelcontext">
                        <p>标签</p>
                        <span>{{ Label }}</span>
                    </div>
                    <div class="labelcontext">
                        <p>归档</p>
                        <span>{{ file }}</span>
                    </div>
                </div>
                <div class="picture" :class="{ 'pictureColor': !isBool }">
                    <img src="../assets/GitHub-fill.png" alt="">
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ElMessage } from 'element-plus'
import { ArrowDown } from '@element-plus/icons-vue'
import { Edit, Delete, } from '@element-plus/icons-vue'
import Pager from './Pager.vue'
import { useRoute } from 'vue-router';
import { useRouter } from "vue-router";
import { inject, provide, reactive, ref, watch } from 'vue'
import { useCounterStore } from '../pinia/Pinia'
const route = useRoute()
const router = useRouter()
const store = useCounterStore()
let article = ref(store.articleTheme.length)
let Label = ref(8)
let file = ref(3)
let fillInTheTitle = ref('')
let fillInTheContent = ref('')
let dialogFormVisible = ref(false)
let Id = ref(store.articleTheme.length)
components: { Pager }
watch(store.articleTheme, (val, oldval) => {
    article.value = store.articleTheme.length
})
// 接受传值
let isBool = inject('Bool')
// 取消按钮
function Cancel() {
    dialogFormVisible.value = false
    fillInTheTitle.value = ''
    fillInTheContent.value = ''
}
// 发布按钮
function Release() {
    if (fillInTheTitle.value == '' || fillInTheContent.value == '') {
        ElMessage({
            message: '请填写必填项',
            type: 'warning',
        })
    } else {
        let Obj = reactive({
            id: Id.value++,
            Title: fillInTheTitle.value,
            Content: fillInTheContent.value
        })
        store.AddData(Obj)
        dialogFormVisible.value = false
        ElMessage({
            message: '发布成功',
            type: 'success',
        })
    }
}
// 删除按钮
function DeleteButton(val) {
    store.Delete(val)
    ElMessage({
        message: '删除成功',
        type: 'success',
    })
}
</script>

<style lang="less" scoped>
.Suspension {
    width: 50px;
    height: 80px;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    align-items: center;
    border-radius: 10px;
    background-color: #fff7f7;
    margin-left: 81vw;
    margin-top: 90px;
    position: fixed;
    z-index: 100;
    /* .el-dropdown{
        >div{
            background-color: red;
        }
    } */
}

.deleteList {
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: 180px;
    height: 4vh;
    border-radius: 2px;

    h3 {
        line-height: 30px;
        font-size: 15px;
        font-weight: 600;
        display: flex;
        justify-content: space-between;

        span {
            display: flex;
            align-items: right;

            .el-button {
                width: 25px;
                height: 25px;
                font-size: 12px;
                opacity: 0;
            }
        }
    }
}

.deleteList:hover {
    background-color: #fdf2f2ce;

    .el-button {
        opacity: 1;
    }
}

.fillIn {
    width: 350px;
    height: 350px;
    margin: auto;
    display: flex;
    flex-direction: column;
    justify-content: space-around;

    span {
        color: red;
    }

    div {
        input {
            width: 350px;
            height: 20px;
        }

        label {
            position: absolute;
            left: 200px;
            font-size: 15px;
            font-weight: 500;
        }
    }

}

.button {
    width: 150px;
    height: 25px;
    display: flex;
    justify-content: space-between;
    margin: auto;

    button {
        width: 55px;
        height: 30px;
        border: 0;
        background-color: #409EFF;
        color: @subjectcolor;
    }
}

.elrow1 {
    /* margin-left: 64vw;
    margin-top: 15px;
    position: fixed;
    z-index: 100; */

    .el-button {
        font-size: 18px;
        width: 35px;
        height: 35px;
        background-color: #fff;
        color: black;
        border: 0;
        transition: all 0.5s ease;
    }
}

.elrow2 {
    /* margin-left: 64vw;
    margin-top: -12px;
    position: fixed;
    z-index: 100; */

    .el-button {
        font-size: 18px;
        width: 35px;
        height: 35px;
        background-color: #fff;
        color: black;
        border: 0;
        transition: all 0.5s ease;
    }
}

.top,
.showarticleContent {
    background-color: #fff;
    color: #222222;
}

.box {
    margin: 20px auto;
    width: 80vw;
    height: 120vh;

    .articleContent {
        width: 80vw;
        height: 120vh;
        display: flex;
        justify-content: space-between;
        margin: 20px auto;

        .articleContentson {
            width: 64vw;
            height: 120vh;
            display: flex;
            flex-direction: column;

            h1 {
                font-size: 35px;
                line-height: 2;
                text-align: center;
            }

            .showarticleContent {
                margin-top: 20px;
                border-radius: 1rem;
                box-shadow: 0 2px 5px #0003, 0 2px 10px #0003;
                width: 64vw;
                height: 23vh;
                color: #24292f;

                h2 {
                    text-align: center;
                    line-height: 2;
                }

                p {
                    display: flex;
                    padding: 0px 20px;
                    line-height: 2;
                }
            }
        }
    }

    .top {
        width: 14vw;
        height: 42vh;
        border-radius: 1rem;
        box-shadow: 0 2px 5px #0003, 0 2px 10px #0003;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: space-around;
        font-size: 18px;
        font-weight: 500;
        margin-top: 90px;

        .name {
            font-size: 23px;
            font-weight: 600;
        }

        .img {
            width: 150px;
            height: 150px;
            overflow: hidden;
            border-radius: 50%;

            img {
                width: 100%;
                height: 100%;
            }
        }

        .label {
            width: 15vw;
            height: 45px;
            display: flex;
            justify-content: space-around;

            .labelcontext {
                display: flex;
                flex-direction: column;
                justify-content: center;
                align-items: center;

                p {
                    font-size: 15px;
                }

                span {
                    font-weight: 600;
                }
            }
        }

        .picture {
            width: 35px;
            height: 35px;
            display: flex;
            justify-content: center;
            align-items: center;
            overflow: hidden;
            border-radius: 50%;

            img {
                width: 100%;
                height: 100%;
            }
        }
    }
}

// 轮播图
.el-carousel__item h3 {
    color: #475669;
    opacity: 0.75;
    line-height: 200px;
    margin: 0;
    text-align: center;
}

.el-carousel__item:nth-child(2n) {
    background-image: url(../assets/backgroud.png);
    background-size: 100% 100%;
}

.el-carousel__item:nth-child(2n-1) {
    background-image: url(../assets/backgroud6.jpg);
    background-size: 100% 100%;
}

.el-carousel__item:nth-child(3) {
    background-image: url(../assets/backgroud3.jpg);
    background-size: 100% 100%;
}

.el-carousel__item:nth-child(4) {
    background-image: url(../assets/backgroud4.jpg);
    background-size: 100% 100%;
}

.el-carousel__item:nth-child(5) {
    background-image: url(../assets/backgroud5.jpg);
    background-size: 100% 100%;
}

.el-carousel__item:nth-child(6) {
    background-image: url(../assets/backgroud7.jpg);
    background-size: 100% 100%;
}

.backgroudColor {
    background-color: @changesubcolor;
}

.TextColor {
    color: white;
}

.pictureColor {
    background-color: white;
}
</style>